<div class="table-tools">
    <eq name="is_admin" value="1">
    <button type="button" onclick="disbanded()" class="btn btn-primary" title="解散房间"><i class="glyphicon glyphicon-remove"></i>解散房间</button>
    </eq>
    <!--<button type="button" class="btn btn-success" title="重新排序资源" onclick="sortQuestions()"><i class="fa fa-copy"></i> 重 排 </button>-->
    <form class="form-inline" method="post" action="__URL__/index" id="search_form"  role="form">
        <input type="hidden" name="pagenum" id="pagenum_hidden" value="{$page.pagenum}">
        <input type="hidden" name="count" value="{$recordcount}">
        <div class="form-group">
            <input type="text" name="user_id" value="{$user_id}" placeholder="请输入擂主id">
            <input type="text" name="id" value="{$id}" placeholder="请输入房间id">
            <select  name="money_type" id="money_type" class="form-control">
                <switch name="money_type">
                    <case value="-1">
                        <option value="-1" selected>金额类型</option>
                        <option value="1">钻石</option>
                        <option value="0">金币</option>
                    </case>
                    <case value="0">
                        <option value="-1">金额类型</option>
                        <option value="1">钻石</option>
                        <option value="0" selected>金币</option>
                    </case>
                    <case value="1">
                        <option value="-1">金额类型</option>
                        <option value="1" selected>钻石</option>
                        <option value="0">金币</option>
                    </case>
                    <default/>
                    <option value="-1" selected>金额类型</option>
                    <option value="1">钻石</option>
                    <option value="0">金币</option>
                </switch>
            </select>
            <select  name="region" id="region" class="form-control">
                <switch name="region">
                    <case value="-1">
                        <option value="-1" selected>战区</option>
                        <option value="1">微信</option>
                        <option value="0">QQ</option>
                    </case>
                    <case value="0">
                        <option value="-1">战区</option>
                        <option value="1">微信</option>
                        <option value="0" selected>QQ</option>
                    </case>
                    <case value="1">
                        <option value="-1">战区</option>
                        <option value="1" selected>微信</option>
                        <option value="0">QQ</option>
                    </case>
                    <default/>
                    <option value="-1" selected>战区</option>
                    <option value="1">微信</option>
                    <option value="0">QQ</option>
                </switch>
            </select>
            <select  name="systems_name" id="systems_name" class="form-control">
                <switch name="systems_name">
                    <case value="-1">
                        <option value="-1" selected>系统</option>
                        <option value="1">IOS</option>
                        <option value="0">安卓</option>
                    </case>
                    <case value="0">
                        <option value="-1">系统</option>
                        <option value="1">IOS</option>
                        <option value="0" selected>安卓</option>
                    </case>
                    <case value="1">
                        <option value="-1">系统</option>
                        <option value="1" selected>IOS</option>
                        <option value="0">安卓</option>
                    </case>
                    <default/>
                    <option value="-1" selected>系统</option>
                    <option value="1">IOS</option>
                    <option value="0">安卓</option>
                </switch>
            </select>
            <select  name="model" id="model" class="form-control">
                <switch name="model">
                    <case value="-1">
                        <option value="-1" selected>比赛模式</option>
                        <option value="4">5V5 征召</option>
                        <option value="3">5V5 王者</option>
                        <option value="2">5V5 深渊</option>
                        <option value="1">3V3 长平</option>
                        <option value="0">1V1 墨家</option>
                    </case>
                    <case value="0">
                        <option value="-1">比赛模式</option>
                        <option value="4">5V5 征召</option>
                        <option value="3">5V5 王者</option>
                        <option value="2">5V5 深渊</option>
                        <option value="1">3V3 长平</option>
                        <option value="0" selected>1V1 墨家</option>
                    </case>
                    <case value="1">
                        <option value="-1">比赛模式</option>
                        <option value="4">5V5 征召</option>
                        <option value="3">5V5 王者</option>
                        <option value="2">5V5 深渊</option>
                        <option value="1" selected>3V3 长平</option>
                        <option value="0">1V1 墨家</option>
                    </case>
                    <case value="2">
                        <option value="-1">比赛模式</option>
                        <option value="4">5V5 征召</option>
                        <option value="3">5V5 王者</option>
                        <option value="2" selected>5V5 深渊</option>
                        <option value="1">3V3 长平</option>
                        <option value="0">1V1 墨家</option>
                    </case>
                    <case value="3">
                        <option value="-1">比赛模式</option>
                        <option value="4">5V5 征召</option>
                        <option value="3" selected>5V5 王者</option>
                        <option value="2">5V5 深渊</option>
                        <option value="1">3V3 长平</option>
                        <option value="0">1V1 墨家</option>
                    </case>
                    <case value="4">
                        <option value="-1">比赛模式</option>
                        <option value="4" selected>5V5 征召</option>
                        <option value="3">5V5 王者</option>
                        <option value="2">5V5 深渊</option>
                        <option value="1">3V3 长平</option>
                        <option value="0">1V1 墨家</option>
                    </case>
                    <default/>
                    <option value="-1" selected>比赛模式</option>
                    <option value="4">5V5 征召</option>
                    <option value="3">5V5 王者</option>
                    <option value="2">5V5 深渊</option>
                    <option value="1">3V3 长平</option>
                    <option value="0">1V1 墨家</option>
                </switch>
            </select>
            <select  name="integral_interval" id="integral_interval" class="form-control">
                <switch name="integral_interval">
                    <case value="-1">
                        <option value="-1" selected>钻石／金币区间</option>
                        <option value="1">100-500</option>
                        <option value="0">100以下</option>
                    </case>
                    <case value="0">
                        <option value="-1">钻石／金币区间</option>
                        <option value="1">100-500</option>
                        <option value="0" selected>100以下</option>
                    </case>
                    <case value="1">
                        <option value="-1">钻石／金币区间</option>
                        <option value="1"  selected>100-500</option>
                        <option value="0">100以下</option>
                    </case>
                    <default/>
                    <option value="-1" selected>钻石／金币区间</option>
                    <option value="1">100-500</option>
                    <option value="0">100以下</option>
                </switch>
            </select>
            <select  name="status" id="status" class="form-control">
                <switch name="status">
                    <case value="-1">
                        <option value="-1" selected>房间状态</option>
                        <option value="3">已解散</option>
                        <option value="2">已结束</option>
                        <option value="1">进行中</option>
                        <option value="0">等待中</option>
                    </case>
                    <case value="0">
                        <option value="-1">房间状态</option>
                        <option value="3">已解散</option>
                        <option value="2">已结束</option>
                        <option value="1">进行中</option>
                        <option value="0" selected>等待中</option>
                    </case>
                    <case value="1">
                        <option value="-1">房间状态</option>
                        <option value="3">已解散</option>
                        <option value="2">已结束</option>
                        <option value="1" selected>进行中</option>
                        <option value="0">等待中</option>
                    </case>
                    <case value="2">
                        <option value="-1">房间状态</option>
                        <option value="3">已解散</option>
                        <option value="2" selected>已结束</option>
                        <option value="1">进行中</option>
                        <option value="0">等待中</option>
                    </case>
                    <case value="3">
                        <option value="-1">房间状态</option>
                        <option value="3" selected>已解散</option>
                        <option value="2">已结束</option>
                        <option value="1">进行中</option>
                        <option value="0">等待中</option>
                    </case>
                    <default/>
                    <option value="-1" selected>房间状态</option>
                    <option value="3">已解散</option>
                    <option value="2">已结束</option>
                    <option value="1">进行中</option>
                    <option value="0">等待中</option>
                </switch>
            </select>
            <button  type="button" onclick="gotoPage(0)">搜索</button>
        </div>
    </form>
    <p>房间列表</p>
</div>

<table id="users-table" class="table table-striped table-hover table-condensed datatable">
    <thead>

    <tr id="user_{$room.id}">
        <th width="50px">ID</th>
        <th>擂主id</th>
        <th>竞争对手id</th>
        <th>所需钻石／金币</th>
        <th>金额类型</th>
        <th>战区</th>
        <th>系统</th>
        <th>段位</th>
        <th>比赛模式</th>
        <th>钻石／金币区间</th>
        <th>房间状态</th>
        <th>创建时间</th>
        <!--<th width="150px">操作</th>-->
        <!--<th width="80px">排序</th>-->
    </tr>
    </thead>
    <tbody>
    <volist name="list" id="room">
        <tr>
            <!--<td width="50px"><input name='id[]' type="checkbox" value="{$room.id}" /></td>-->
            <td class="question-name">{$room.id}</td>
            <td class="question-name">{$room.user_id}</td>
            <td class="question-name">{$room.opponent_id}</td>
            <td class="question-name">{$room.integral}</td>
            <td class="question-name">
                <switch name="room.money_type">
                    <case value="0">
                        金币
                    </case>
                    <case value="1">
                        钻石
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <switch name="room.region">
                    <case value="0">
                        QQ
                    </case>
                    <case value="1">
                        微信
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <switch name="room.systems_name">
                    <case value="0">
                        安卓
                    </case>
                    <case value="1">
                        IOS
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <switch name="room.level">
                    <case value="1">
                        青铜
                    </case>
                    <case value="2">
                        白银
                    </case>
                    <case value="3">
                        黄金
                    </case>
                    <case value="4">
                        铂金
                    </case>
                    <case value="5">
                        钻石
                    </case>
                    <case value="6">
                        星耀
                    </case>
                    <case value="7">
                        王者
                    </case>
                </switch>
            </td>
            <td class="question-name">
                <switch name="room.model">
                    <case value="0">
                        自由擂 1v1 墨家
                    </case>
                    <case value="1">
                        自由擂 3V3 长平
                    </case>
                    <case value="2">
                        自由擂 5V5 深渊
                    </case>
                    <case value="3">
                        自由擂 5V5 王者
                    </case>
                    <case value="4">
                        自由擂 5V5 征召
                    </case>
                    <case value="5">
                        输赢排位赛
                    </case>
                    <case value="6">
                        排位擂 输赢 「大」
                    </case>
                    <case value="7">
                        排位擂 输赢 「小」
                    </case>
                    <case value="8">
                        排位擂 输赢 「单」
                    </case>
                    <case value="9">
                        排位擂 输赢 「双」
                    </case>

                </switch>
            </td>
            <td class="question-name">
                <switch name="room.integral_interval">
                    <case value="0">
                        100以下
                    </case>
                    <case value="1">
                        100-500
                    </case>
                </switch>
            </td>
            <td class="question-name" id="status_{$room.id}">
                <switch name="room.status">
                    <case value="0">
                        等待中
                    </case>
                    <case value="1">
                        进行中
                    </case>
                    <case value="2">
                        已结束
                    </case>
                    <case value="3">
                        已解散
                    </case>
                </switch>
            </td>
            <td class="question-name">{$room.create_time|date='Y-m-d H:i',###}</td>
            <td width="150px">
                <if condition="$room.status neq 3 AND $room.status neq 2">
                    <div id="dissolve_{$room.id}">

                    <a onclick="verify(this)" data-id="{$room.id}" class="btn btn-default btn-rounded btn-condensed btn-sm" title="解散房间"><span class="fa fa-pencil">解散房间</span>
                    </a>

                    </div>
                </if>
            </td>
        </tr>
    </volist>
    </tbody>
</table>
<nav style="float:right">
    <spen class="total">共 {$recordcount}条记录</spen>
    <div class="fr">
        <ul class="pagination">
            <eq name="page['pagenum']" value="1">
                <li class="disabled">
                    <else/>
                <li>
            </eq>
            <a href="#" onclick="gotoPage('1')">«</a></li>
            <foreach name="page.pagenums" item="vo">
                <eq name="page['pagenum']" value="$vo">
                    <li class="active"><a href="#">{$vo}</a></li>
                    <else/>
                    <li><a href="#" onclick="gotoPage('{$vo}')">{$vo}</a></li>
                </eq>
            </foreach>
            <eq name="page['pagenum']" value="$page.endPage">
                <li class="disabled">
                    <else/>
                <li>
            </eq>
            <a href="#" onclick="gotoPage('{$page.totalpage}')">»</a></li>
        </ul>
    </div>
</nav>

<div class="modal fade" id="hint_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" >提示</h4>
            </div>
            <div class="modal-body" id="hint_content">
            </div>
            <div class="modal-footer">
                <button type="button"  class="btn btn-default" data-dismiss="modal">关闭</button>
                <!--<button type="button" class="btn btn-primary">Save changes</button>-->
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="verify_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="verify_modal_title">审核</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="verify_remark">请输入审核信息</label>
                    <textarea type="text" class="form-control" id="verify_remark" placeholder="请输入审核信息"></textarea>
                </div>
                <div id="is_poundage_div">
                    <div class="radio">
                        <label>
                            <input type="radio" name="is_poundage" value="1">
                            <span id="user_content">需要手续费</span>
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="is_poundage"  value="0">
                            <span id="opponent_content">不需要手续费</span>
                        </label>
                    </div>
                </div>
                <div id="payer_div" hidden>
                    <div class="radio">
                        <label>
                            <input type="radio" name="payer" value="0">
                            <span >擂主支付手续费</span>
                        </label>
                    </div>
                    <div class="radio">
                        <label>
                            <input type="radio" name="payer"  value="1">
                            <span >打擂者支付手续费</span>
                        </label>
                    </div>
                </div>
            </div>
            <input type="hidden" name="log_id" id="log_id">
            <input type="hidden" name="verify_type" id="verify_type">
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="verifyConfirm()" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/layer/layer.js"></script>
<script>
    function disbanded(){
        layer.confirm('您确定要解散未进行比赛的房间？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            layer.closeAll();
            $.ajax({
                type: "POST",
                url: "__URL__/dissolveAll",
                dataType: "json",
                success: function (data) {

                    console.info(data);
                    $("#hint_content").empty().append(data.message);
                    $("#hint_modal").modal();
                    if(data.success){
//                        window.location.reload();
                    }
                },
                error: function (data) {
                    console.info(data);
                    $("#hint_content").empty().append("请求超时！");
                    $("#hint_modal").modal();
                }
            });
        }, function(){

        });
    }
    $("input:radio[name=is_poundage]").change(function () {
            var value = $(this).val();
            if(value == 0){
                $('#payer_div').hide();
            }else{
                $('#payer_div').show();
            }
        }
    );
        function gotoPage(pagenum) {
        //提交form
        $('#pagenum_hidden').val(pagenum);
        $('#search_form').submit();
    }
    function verify(obj){
        var id = $(obj).data('id');
        $('#log_id').val(id);
        $('#is_poundage_div').show();
        $('#verify_modal_title').empty().append('解散房间');
        $('#verify_modal').modal();
    }
    function verifyConfirm(){
        $('#verify_modal').modal('hide');
        var remark = $('#verify_remark').val();
        console.info(remark);
        var log_id = $('#log_id').val();
        var verify_type = $('#verify_type').val();
        var is_poundage = $("input[name='is_poundage']:checked").val();
        var payer = $("input[name='payer']:checked").val();

        if(verify_type == 1 && is_poundage == undefined){
            $("#hint_content").empty().append("请选择是否需要手续费！");
            $("#hint_modal").modal();
            return;
        }
        if(is_poundage == 1 && payer == undefined){
            $("#hint_content").empty().append("请选择手续费支付者！");
            $("#hint_modal").modal();
            return;
        }
        if(remark == ''){
            $("#hint_content").empty().append("请填写备注信息！");
            $("#hint_modal").modal();
            return;
        }
        if(log_id == ''){
            return;
        }
        $.ajax({
            type: "POST",
            url: "__URL__/dissolve",
            data: {remark: remark,room_id:log_id,is_poundage:is_poundage,payer:payer},
            dataType: "json",
            success: function (data) {
                console.info(data);
                $("#hint_content").empty().append(data.message);
                $("#hint_modal").modal();
                if(data.success){
                    $('#dissolve_'+log_id).hide();
                    $('#status_'+log_id).empty().append('已解散');
                }
            },
            error: function (data) {
                console.info(data);
                $("#hint_content").empty().append("请求超时！");
                $("#hint_modal").modal();
            }
        });
    }
</script>